package com.we823.project.model.product;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.we823.project.common.web.status.PlanStatus;
import com.we823.project.common.web.status.TaskType;
import com.we823.project.model.BaseModelWithDate;
import com.we823.project.model.UserModel;
import com.we823.project.model.repo.MaterialModel;

@Entity
@Table(name="we_plan")
public class PlanModel extends BaseModelWithDate {
	private static final long serialVersionUID = 1L;

	private String code;

	private String name;
	
	@Column(name="material_code")
	private String materialCode;
	
	@Transient
	private MaterialModel material;
	
	@Transient
	private String materialModel;
	@Transient
	private String unit;
	
	@Enumerated(EnumType.STRING)
	private PlanStatus status=PlanStatus.NoFinish;
	@Transient
	private String statusMessage;

	@Column(name="old_id")
	private int oldId;
	
	private String inputer;
	
	@ManyToOne
	@JoinColumn(name="user_id")
	private UserModel user;
	
	private String username;

	@Column(name="start_date")
	private Date startDate;
	
	@Column(name="finish_date")
	private Date finishDate;
	
	@Enumerated(EnumType.STRING)
	private  TaskType type = TaskType.normal;
	@Transient
	private String typeMessage;
	
	@Column(name="plan_num")
	private Float planNum=0f;
	
	/**
	 * 最后一道工序
	 */
	@Transient
	private PlanDetailModel lastPlanDetail;
	public PlanModel() {
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getInputer() {
		return this.inputer;
	}

	public void setInputer(String inputer) {
		this.inputer = inputer;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getOldId() {
		return this.oldId;
	}

	public void setOldId(int oldId) {
		this.oldId = oldId;
	}

	
	public PlanStatus getStatus() {
		return this.status;
	}

	public void setStatus(PlanStatus status) {
		this.status = status;
	}

	public UserModel getUser() {
		return this.user;
	}

	public void setUser(UserModel user) {
		this.user = user;
	}

	public String getStatusMessage() {
		if (status!=null && StringUtils.isEmpty(statusMessage)) {
			statusMessage = status.getDisplay();
		}
		return statusMessage;
	}

	public void setStatusMessage(String statusMessage) {
		this.statusMessage = statusMessage;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	@JSONField(format="yyyy-MM-dd")
	public Date getFinishDate() {
		return finishDate;
	}

	public void setFinishDate(Date finishDate) {
		this.finishDate = finishDate;
	}

	public String getMaterialCode() {
		return materialCode;
	}

	public void setMaterialCode(String materialCode) {
		this.materialCode = materialCode;
	}

	public TaskType getType() {
		if (type==null) {
			type = TaskType.normal;
		}
		return type;
	}

	public void setType(TaskType type) {
		if (type==null) {
			this.type = TaskType.normal;
		}
		this.type = type;
	}

	public Float getPlanNum() {
		return planNum;
	}

	public void setPlanNum(Float planNum) {
		this.planNum = planNum;
	}

	public String getMaterialModel() {
		return materialModel;
	}

	public void setMaterialModel(String materialModel) {
		this.materialModel = materialModel;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

    public String getTypeMessage(){
    	if (type!=null) {
			return type.getType();
		}
    	return "";
    }

	public MaterialModel getMaterial() {
		return material;
	}

	public void setMaterial(MaterialModel material) {
		this.material = material;
	}

	public PlanDetailModel getLastPlanDetail() {
		return lastPlanDetail;
	}

	public void setLastPlanDetail(PlanDetailModel lastPlanDetail) {
		this.lastPlanDetail = lastPlanDetail;
	}
    
}